package some.point.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import some.point.dao.PointDao;
import some.point.domain.PointCommand;

@Controller
public class PointDetailController {
	
	@Autowired
	private PointDao pointDao;
	
	@RequestMapping("/pointDetail.do")
	public ModelAndView pointDetail(HttpSession session){
		
		String id = (String)session.getAttribute("id");
		
		List<PointCommand> list = null;
		list = pointDao.pointList(id);
		
		int totalPoint = 0;
		
		for(PointCommand po : list){
			totalPoint += po.getPoint();
		}
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("pointDetail");
		mav.addObject("pointList", list);
		mav.addObject("totalPoint", totalPoint);
		mav.addObject("id", id);
		
		return mav;
	}
}
